var app = getApp();
var url = app.globalData.url;
var merchantId;

const defHeaders = {
  'Content-Type': 'application/json;charset=UTF-8',
  'Accept': 'application/json',
};

Page({
  data: {
    list: [],
    list_hui: [],
  },
  onLoad() {
    var that = this;
    // 取出merchantId
    wx.getStorage({
      key: 'merchantId',
      success: function (res) {
        merchantId = res.data.merchantId;

        wx.request({

          url: url + '/cardMembership/getCardDepositConfig.do',
          method: 'get',
          data: {
            merchantId: merchantId,
          },
          headers: {
            defHeaders
          },
          dataType: 'json',
          success: function (res) {
            // console.log(res)
            var arr = [];
            var list = res.data.body.cardDepositBenefitConfigList
            for (var i = 0; i < list.length; i++) {
              list[i].name = list[i].comment;
              arr.push(list[i]);
            }
            // console.log(name)
            that.setData({
              list: arr,
            });
          },
          fail: function (res) {
            // my.alert({
            //   content: res,
            // });
          },
          complete: function (res) {
            // my.hideLoading();
          }
        });
        // 等级权益
        wx.request({

          url: url + '/cardMembership/getList.do',
          method: 'get',
          data: {
            merchantId: merchantId,
          },
          headers: {
            'Content-Type': 'application/json;charset=UTF-8',
            'Accept': 'application/json',
          },
          dataType: 'json',
          success: function (res) {
            console.log(res)
            var arr = [];
            var list = res.data.body
            for (var j = 0; j < list.length; j++) {
              list[j].title = list[j].name;
              list[j].growthBalance = list[j].growthBalance;
              list[j].growthPoint = list[j].growthPoint;
              list[j].ruleBalance = list[j].ruleBalance;
              list[j].rulePoint = list[j].rulePoint;
              list[j].exchangePoint = list[j].exchangePoint;
              list[j].exchangeBalance = list[j].exchangeBalance;
              arr.push(list[j]);

            }
            // console.log(name)
            that.setData({
              list_hui: arr,
              none: "none"
            });
            // my.hideLoading();
          },
          fail: function (res) {
            // my.alert({
            //   content: res,
            // });
          },
          complete: function (res) {
            // my.hideLoading();
          }
        });

      },
      fail: function (res) {
        // my.alert({ content: "加载失败" });
      }
    });
    // console.log(merchantId)
    //获取会员规则

  },
  onPullDownRefresh() {
    // 页面被下拉
    wx.stopPullDownRefresh()
  },
});
